package com.hll.model.query;

/**
 * Created by CGL on 2017-06-24 14:18:46.
 */
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class BaseExample implements Serializable {
    private static final long serialVersionUID = 99999L;
    public final String UNDERLINE = "_";
    List<String> fields;
    List<Integer> limit;

    public BaseExample() {
    }

    public void setFields(List<String> fields) {
        ArrayList columns = new ArrayList();
        Iterator var4 = fields.iterator();

        while(var4.hasNext()) {
            String column = (String)var4.next();
            String field = this.toUnderlineCase(column);
            columns.add(field);
        }

        this.fields = columns;
    }

    public void setColunms(List<String> columns) {
        this.fields = columns;
    }

    private String toUnderlineCase(String camelCaseStr) {
        if(camelCaseStr == null) {
            return null;
        } else {
            int length = camelCaseStr.length();
            StringBuilder sb = new StringBuilder();
            boolean isPreUpperCase = false;

            for(int i = 0; i < length; ++i) {
                char c = camelCaseStr.charAt(i);
                boolean isNextUpperCase = true;
                if(i < length - 1) {
                    isNextUpperCase = Character.isUpperCase(camelCaseStr.charAt(i + 1));
                }

                if(!Character.isUpperCase(c)) {
                    isPreUpperCase = false;
                } else {
                    if((!isPreUpperCase || !isNextUpperCase) && i > 0) {
                        sb.append("_");
                    }

                    isPreUpperCase = true;
                }

                sb.append(Character.toLowerCase(c));
            }

            return sb.toString();
        }
    }

    public void setLimit(List<Integer> limit) {
        this.limit = limit;
    }

    public List<String> getFields() {
        return this.fields;
    }
}
